//
//  AYMProvinceView.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/7.
//  Copyright © 2016年 ayumi. All rights reserved.
//

//
//  AYMProvinceView.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/7.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMProvinceView.h"

@implementation AYMProvinceView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        //布局界面
        [self setupUI];        
    }
    return self;
}

-(void)setupUI{
    
    [self setupCoverView];
    //白色弹框
    UIView *alertView = [[UIView alloc]init];
    alertView.layer.cornerRadius = 10;
    alertView.clipsToBounds = YES;
    alertView.backgroundColor = [UIColor whiteColor];
    [self addSubview:alertView];
    [alertView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(300);
        make.height.equalTo(400);
    }];
    
    self.provinceTableView = [[UITableView alloc] init];
    [alertView addSubview:self.provinceTableView];
    [self.provinceTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(alertView.left).offset(35);
        make.right.equalTo(alertView.right).offset(-35);
        make.top.equalTo(alertView.top).offset(62);
        make.bottom.equalTo(alertView.bottom).offset(-62);

    }];
    
    UILabel *provinceLabel = [UILabel textColor:commonTextColor font:personalCellFont];
    provinceLabel.text = @"设置省份";
    [alertView addSubview:provinceLabel];
    
    [provinceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(alertView.centerX);
        make.top.equalTo(alertView.top).offset(20);
        
    }];
    
    UIButton *cancelButton =[UIButton titleName:@"取消" NormalColor:[UIColor darkGrayColor] font:personalCellFont];
    [alertView addSubview:cancelButton];
    [cancelButton addTarget:self action:@selector(didClickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.backgroundColor = [UIColor lightGrayColor];
    [alertView addSubview:imgView];
    
    UIButton *addButton = [UIButton titleName:@"提交" NormalColor:commonTextColor font:personalCellFont];
    [addButton addTarget:self action:@selector(didComposeClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:addButton];
    
    UIImageView *lineView =[[ UIImageView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [alertView addSubview:lineView];
    
    
    [cancelButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(alertView.left);
        make.bottom.equalTo(alertView.bottom);
        make.height.equalTo(55);
        make.width.equalTo(addButton.width);
        
    }];
    
    [imgView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(1);
        make.left.equalTo(cancelButton.right);
        make.height.equalTo(cancelButton.height);
        make.right.equalTo(addButton.left);
        make.bottom.equalTo(alertView.bottom);
    }];
    
    [addButton makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(alertView.bottom);
        make.right.equalTo(alertView.right);
        make.height.equalTo(cancelButton.height);
        make.width.equalTo(cancelButton.width);
        
    }];
    
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(alertView.left);
        make.right.equalTo(alertView.right);
        make.bottom.equalTo(cancelButton.top);
        make.height.equalTo(1);
    }];
}
#pragma mark - 按钮点击事件
// 点击提交按钮
-(void)didComposeClick{
    
    if ([self.delegate respondsToSelector:@selector(provinceViewCommit:)]) {
        [self.delegate provinceViewCommit:self];
    }
}
//点击取消
-(void)didClickCancelBtn{

    if ([self.delegate respondsToSelector:@selector(provinceViewCancel:)]) {
        [self.delegate provinceViewCancel:self];
    }
}

#pragma mark - 设置coverView
-(void)setupCoverView{
    
    UIView* coverView = [[UIView alloc] initWithFrame:self.bounds];
    coverView.backgroundColor = [UIColor blackColor];
    coverView.alpha = 0.3;
    [self addSubview:coverView];
    
}


@end
